#编译器设置
CXX = g++
CXXFLAGS = -Wall -Wextra -g -std=c++11

#目录设置
SRCDIR = src
BUILDDIR = build
TARGET = Server

#库连接
LIBS = -llog4cpp -lmysqlclient -lcrypt

#自动查找所有源文件
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(SOURCES:$(SRCDIR)/%.cpp=$(BUILDDIR)/%.o)

#默认目标
all: $(TARGET)

#生成可执行文件在项目目录下
$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

#编译源文件到build目录中的目标文件
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp | $(BUILDDIR)
	$(CXX) $(CXXFLAGS) -c $< -o $@
#创建build目录
$(BUILDDIR):
	mkdir -p $(BUILDDIR)
#安装目标
install: $(TARGET)
	sudo chown root:root $(TARGET)
	sudo chmod u+s $(TARGET)

#运行目标
run: $(TARGET)
	sudo ./$(TARGET)
#清理
clean:
	rm -rf $(TARGET) $(BUILDDIR)
.PHONY: all clean
